package com.ruoyi.business.controller;

import com.ruoyi.business.domain.FileBorrowingRegistration;
import com.ruoyi.business.service.IFileBorrowingRegistrationService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 借阅登记Controller
 *
 * @author sal
 * @date 2024-11-12
 */
@RestController
@RequestMapping("/business/fileBorrowingRegistration")
public class FileBorrowingRegistrationController extends BaseController
{
    @Autowired
    private IFileBorrowingRegistrationService fileBorrowingRegistrationService;

    /**
     * 查询借阅登记列表
     */
    @PreAuthorize("@ss.hasPermi('business:fileBorrowingRegistration:list')")
    @GetMapping("/list")
    public TableDataInfo<FileBorrowingRegistration> list(FileBorrowingRegistration fileBorrowingRegistration, PageQuery pageQuery)
    {
        return fileBorrowingRegistrationService.selectPageFileBorrowingRegistrationList(fileBorrowingRegistration,pageQuery);
//        startPage();
//        List<FileBorrowingRegistration> list = fileBorrowingRegistrationService.selectFileBorrowingRegistrationList(fileBorrowingRegistration);
//        return getDataTable(list);
    }

    /**
     * 导出借阅登记列表
     */
    @PreAuthorize("@ss.hasPermi('business:fileBorrowingRegistration:export')")
    @Log(title = "借阅登记", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(FileBorrowingRegistration fileBorrowingRegistration, HttpServletResponse response)
    {
        List<FileBorrowingRegistration> list = fileBorrowingRegistrationService.selectFileBorrowingRegistrationList(fileBorrowingRegistration);
        ExcelUtil.exportExcel(list, "借阅登记", FileBorrowingRegistration.class, response);
//        ExcelUtil<FileBorrowingRegistration> util = new ExcelUtil<FileBorrowingRegistration>(FileBorrowingRegistration.class);
//        return util.exportExcel(list, "fileBorrowingRegistration");
    }

    /**
     * 获取借阅登记详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:fileBorrowingRegistration:query')")
    @GetMapping(value = "/{id}")
    public R<FileBorrowingRegistration> getInfo(@PathVariable("id") Long id)
    {
        return R.ok(fileBorrowingRegistrationService.selectFileBorrowingRegistrationById(id));
    }

    /**
     * 新增借阅登记
     */
    @PreAuthorize("@ss.hasPermi('business:fileBorrowingRegistration:add')")
    @Log(title = "借阅登记", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody FileBorrowingRegistration fileBorrowingRegistration)
    {
        fileBorrowingRegistration.setStatus(0L);
        return toAjax(fileBorrowingRegistrationService.insertFileBorrowingRegistration(fileBorrowingRegistration));
    }

    /**
     * 修改借阅登记
     */
    @PreAuthorize("@ss.hasPermi('business:fileBorrowingRegistration:edit')")
    @Log(title = "借阅登记", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody FileBorrowingRegistration fileBorrowingRegistration)
    {
        return toAjax(fileBorrowingRegistrationService.updateFileBorrowingRegistration(fileBorrowingRegistration));
    }

    /**
     * 归还
     */
    @PreAuthorize("@ss.hasPermi('business:fileBorrowingRegistration:edit')")
    @Log(title = "借阅登记", businessType = BusinessType.UPDATE)
    @PutMapping("restitution")
    public R restitution(@RequestBody FileBorrowingRegistration fileBorrowingRegistration)
    {
        fileBorrowingRegistration.setStatus(1L);
        return toAjax(fileBorrowingRegistrationService.updateFileBorrowingRegistration(fileBorrowingRegistration));
    }

    /**
     * 删除借阅登记
     */
    @PreAuthorize("@ss.hasPermi('business:fileBorrowingRegistration:remove')")
    @Log(title = "借阅登记", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public R remove(@PathVariable Long[] ids)
    {
        return toAjax(fileBorrowingRegistrationService.deleteFileBorrowingRegistrationByIds(ids));
    }
}
